package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.RewardRecord;
import com.example.elderlycare.dao.mapper.RewardRecordMapper;
import com.example.elderlycare.service.RewardService;
import com.example.elderlycare.service.entity.RewardRecordItem;
import com.example.elderlycare.service.entity.RewardRecordListResponseBody;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class RewardServiceImpl extends ServiceImpl<RewardRecordMapper, RewardRecord>
        implements RewardService {

    @Resource
    RewardRecordMapper rewardRecordMapper;

    @Override
    public RewardRecordListResponseBody queryRewardRecords(Map<String, Object> params) {
        int total = rewardRecordMapper.getRewardRecordsCount(params);
        List<RewardRecord> rewardRecords = rewardRecordMapper.queryRewardRecords(params);
        List<RewardRecordItem> rewardRecordItemList = new ArrayList<>();
        rewardRecords.forEach(rewardRecord -> {
            RewardRecordItem item = RewardRecordItem.builder()
                    .id(rewardRecord.getId())
                    .rewardsDate(rewardRecord.getRewardsDate())
                    .employeeId(rewardRecord.getEmployeeId())
                    .employeeName(rewardRecord.getEmployeeName())
                    .reason(rewardRecord.getReason())
                    .rewardsCount(rewardRecord.getRewardsCount())
                    .rewardsType(rewardRecord.getRewardsType())
                    .remark(rewardRecord.getRemark())
                    .build();
            rewardRecordItemList.add(item);
        });

        return RewardRecordListResponseBody.builder()
                .total(total)
                .rewardRecordList(rewardRecordItemList)
                .build();
    }
}
